package com.xmall.controller.wx;

import com.xmall.bean.bo.CheckList;
import com.xmall.bean.table.Cart;
import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.vo.CartVo;
import com.xmall.bean.vo.CheckoutCartVo;
import com.xmall.service.CartServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/cart")
public class WxCartController {
    @Autowired
    CartServcie cartServcie;

    @RequestMapping("index")
    public BaseRespVo indexCart() {
        CartVo cartVo = cartServcie.indexCart();

        return BaseRespVo.ok(cartVo);
    }

    @RequestMapping("update")
    public BaseRespVo updateCart(@RequestBody Cart cart) {

        cartServcie.updateCart(cart);
        return BaseRespVo.ok();
    }

    @RequestMapping("checked")
    public BaseRespVo checkCart(@RequestBody CheckList checkList) {

        CartVo cartVo = cartServcie.checkCart(checkList);
        return BaseRespVo.ok(cartVo);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteCart(@RequestBody CheckList checkList) {

        CartVo cartVo = cartServcie.delete(checkList);
        return BaseRespVo.ok(cartVo);
    }


    @RequestMapping("goodscount")
    public BaseRespVo goodscountCart() {

        Integer integer = cartServcie.goodscount();
        return BaseRespVo.ok(integer);
    }

    @RequestMapping("add")
    public BaseRespVo addCart(@RequestBody Cart cart) {

        Integer integer = cartServcie.add(cart);
        return BaseRespVo.ok(integer);
    }

    @RequestMapping("fastadd")
    public BaseRespVo fastaddCart(@RequestBody Cart cart) {

        Integer integer = cartServcie.fastadd(cart);
        return BaseRespVo.ok(integer);
    }

    @RequestMapping("checkout")
    public BaseRespVo checkoutCart(Integer cartId, Integer addressId, Integer couponId, Integer grouponRulesId) {

        CheckoutCartVo cartCheckoutVo = cartServcie.checkoutCart(cartId, addressId, couponId, grouponRulesId);
        return BaseRespVo.ok(cartCheckoutVo);
    }


}
